<template>
  <el-dialog @close="shjsdCancel('shjsdRuleForm')" :close-on-click-modal="false" title="审核结算单"
    :visible.sync="shjsdVisible" width="900px">
    <div class="scroll-view">
      <el-descriptions :column="2" border>
        <el-descriptions-item label="合同签约金额" v-if="fieldShowFunc('js_contract_price')">{{ jsdData.contract_price ? jsdData.contract_price + '元' : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="增减项总金额" v-if="fieldShowFunc('changes_amount')">{{ jsdData.changes_amount ? jsdData.changes_amount + '元' : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="应结算金额" v-if="fieldShowFunc('settlement_amount')">{{ jsdData.settlement_amount ? jsdData.settlement_amount + '元' : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="现场采购成本（结算）" v-if="fieldShowFunc('js_procurement_cost')">{{ jsdData.procurement_cost ? jsdData.procurement_cost + '元' : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="公司集采成本" v-if="fieldShowFunc('js_centralized_procurement_cost')">{{
          jsdData.centralized_procurement_cost ? jsdData.centralized_procurement_cost + '元' : '--'
        }}</el-descriptions-item>
        <el-descriptions-item label="已付款金额" v-if="fieldShowFunc('js_paid_amount')">{{ jsdData.paid_amount ? jsdData.paid_amount + '元' : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="待付款金额" v-if="fieldShowFunc('js_unpaid_amount')">{{ jsdData.unpaid_amount ? jsdData.unpaid_amount + '元' : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="结算税金" v-if="fieldShowFunc('js_settlement_taxes')">{{ jsdData.settlement_taxes ? jsdData.settlement_taxes + '元' : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="成本金额" v-if="fieldShowFunc('js_settlement_cost_amount')">{{ jsdData.settlement_cost_amount ? jsdData.settlement_cost_amount + '元' :
          '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="利润率" v-if="fieldShowFunc('js_settlement_profit_margin')">{{ jsdData.settlement_profit_margin ? jsdData.settlement_profit_margin + '%' : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="结算文件" v-if="fieldShowFunc('js_settlement_file')" :span="2">
          <div class="flex ac fw">
            <div @click="$fileViewHandle(item)" class="file-name" v-for="(item, index) in jsdData.settlement_file"
              :key="index">{{ item.file_name }}</div>
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="工程量清单" v-if="fieldShowFunc('js_inventory_file')" :span="2">
          <div class="flex ac fw">
            <div @click="$fileViewHandle(item)" class="file-name" v-for="(item, index) in jsdData.inventory_file"
              :key="index">{{ item.file_name }}</div>
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="利润单文件" v-if="fieldShowFunc('js_profit_statement_file')" :span="2">
          <div class="flex ac fw">
            <div @click="$fileViewHandle(item)" class="file-name" v-for="(item, index) in jsdData.profit_statement_file"
              :key="index">{{ item.file_name }}</div>
          </div>
        </el-descriptions-item>
      </el-descriptions>
      <el-form :model="shjsdRuleForm" :rules="shjsdRules" ref="shjsdRuleForm" label-position="top">
        <el-form-item label="" prop="reviewPassed">
          <el-radio-group v-model="shjsdRuleForm.reviewPassed" size="small">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input :rows="4" class="input-box" v-model="shjsdRuleForm.remark" type="textarea"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer">
      <el-button @click="shjsdCancel('shjsdRuleForm')">关闭</el-button>
      <el-button type="primary" @click="shjsdSubmit('shjsdRuleForm')" :disabled="diaLoading" :loading="diaLoading">确
        定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import projectApi from "@/api/projectApi";
import companyApi from "@/api/companyApi";
import adminApi from "@/api/adminApi";
import { getUserInfo } from "@/utils/auth";
import foremanApi from "@/api/foremanApi";

export default {
  name: "",
  props: {
    addDialogVisible: {
      type: Boolean,
      default: false,
      required: false,
    },
    project_id: {
      required: false,
    },
    jsdData: {
      required: false,
    },
    fieldList:{
      required: false,
    }
  },
  data() {
    return {
      shjsdRuleForm: {
        remark: "",
        reviewPassed: 1,
      },
      shjsdVisible: false,
      shjsdRules: {},
      diaLoading: false,
    };
  },
  watch: {
    addDialogVisible(val1, val2) {
      this.shjsdVisible = this.addDialogVisible;
    },
  },
  computed: {},
  mounted() { },
  methods: {
    // 判断是否显示
    fieldShowFunc(field) {
      let fieldList = this.fieldList;
      return fieldList[field] == undefined ? true : fieldList[field];
    },
    shjsdCancel(formName) {
      this.shjsdRuleForm = {
        reviewPassed: 1,
        remark: "",
      };
      this.$nextTick(() => {
        this.$refs[formName].clearValidate();
        this.$emit("onClose", true);
      });
    },
    shjsdSubmit(formName) {
      let shjsdRuleForm = this.shjsdRuleForm;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.diaLoading = true;
          if (shjsdRuleForm.reviewPassed == 2) {
            projectApi
              .settlementStatementRejected({
                project_id: this.project_id,
                remark: shjsdRuleForm.remark,
              })
              .then((res) => {
                console.log(res, "审核结算单");
                this.diaLoading = false;
                if (res.code == 200) {
                  this.$emit("onSuccess", true);
                }
                this.$message({
                  type: res.code == 200 ? "success" : "warning",
                  message: res.code == 200 ? "处理成功" : res.message,
                });
              })
              .catch((err) => {
                this.diaLoading = false;
                this.$message({
                  type: "warning",
                  message: err.message,
                });
              });
            return;
          }
          projectApi
            .settlementStatementPassed({
              project_id: this.project_id,
              remark: shjsdRuleForm.remark,
            })
            .then((res) => {
              console.log(res, "审核结算单");
              this.diaLoading = false;
              if (res.code == 200) {
                this.$emit("onSuccess", true);
              }
              this.$message({
                type: res.code == 200 ? "success" : "warning",
                message: res.code == 200 ? "处理成功" : res.message,
              });
            })
            .catch((err) => {
              this.diaLoading = false;
              this.$message({
                type: "warning",
                message: err.message,
              });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>